import { int, mysqlTable, serial, varchar } from 'drizzle-orm/mysql-core';
import { timestamps } from './common';
import roles from './roles';

export const users = mysqlTable('users', {
  id: int().primaryKey().autoincrement(),
  name: varchar({ length: 255 }).notNull(),
  email: varchar({ length: 255 }).notNull().unique(),
  password: varchar({ length: 255 }).notNull(),
  salt: varchar({ length: 255 }).notNull(),
  role_id: int().notNull().default(1).references(() => roles.id),
  ...timestamps,
});

// 在 drizzle 里，有 .$inferSelect 和 .$inferInsert 这两种类型

export type User = typeof users.$inferSelect;
